﻿// JScript File
function check_email(e) {
 ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
 for(i=0; i < e.length ;i++){
  if(ok.indexOf(e.charAt(i))<0){
   return (false);
  }
 }
 if (document.images) {
  re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
  re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
  if (!e.match(re) && e.match(re_two)) {
   return (true);
  }
  return (false);
 }
 return (true);
}

function checkform ()
 {
 if (document.form1.txtUserName.value == "") 
 {
    alert("You have not typed a correct value for the input field 'name'.");
    document.form1.txtUserName.focus();
    return(false);
 }
 if (document.form1.txtEmail.value != "" && !check_email(document.form1.txtEmail.value)) {
    alert("You have not typed a correct value for the input field 'email'.");
    document.form1.txtEmail.focus();
    return(false);
 }
 if (document.form1.txtMesage.value.length < 3) {
    alert("You have not typed a correct value for the input field 'message'.");
    document.form1.txtMesage.focus();
    return(false);
 }
 
 var messtext = document.form1.txtMesage.value.toLowerCase();
 if (messtext && (messtext.indexOf("[url")>-1 || messtext.indexOf("<a ")>-1)) {
    alert("Please type a normal message text.\n\nNote that HTML tags or BB-codes are not allowed!");
    document.form1.txtMesage.focus();
    return(false);
 } 

 return (true);
}

function check_pass(p) {
	ok = "1234567890qwertyuiopasdfghjklzxcvbnm.-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < p.length ;i++){
		if(ok.indexOf(p.charAt(i))<0){
			return (false);
		}
	}
	return (true);
}

function checkRegForm () {  

 if (document.getElementById("ctl00$ContentPlaceHolder1$txtUserName").value == "") {
    alert("Please enter your name.");
    document.getElementById("ctl00$ContentPlaceHolder1$txtUserName").focus();
    return(false);
  }
  

  if (document.getElementById("ctl00$ContentPlaceHolder1$txtUserEmail").value == "" || !check_email(document.getElementById("ctl00$ContentPlaceHolder1$txtUserEmail").value)) {
    alert("Please enter your email address.");
    document.getElementById("ctl00$ContentPlaceHolder1$txtUserEmail").focus();
    return(false);
  }
  /*
  if (document.getElementById("ctl00$ContentPlaceHolder1$txtUserWebsite").value == "" || document.getElementById("ctl00$ContentPlaceHolder1$txtUserWebsite").value == "http://") {
    alert("Please enter your website address.");
    document.getElementById("ctl00$ContentPlaceHolder1$txtUserWebsite").focus();
    return(false);
  }
  */
  
  if (document.getElementById("ctl00$ContentPlaceHolder1$txtTitle").value == "") {
    alert("Please enter a title for your guestbook.");
    document.getElementById("ctl00$ContentPlaceHolder1$txtTitle").focus();
    return(false);
  }

  if (document.getElementById("ctl00$ContentPlaceHolder1$txtPassword").value == "" || !check_pass(document.getElementById("ctl00$ContentPlaceHolder1$txtPassword").value)) {
    alert("Please enter a password.\n\nNote that only English letters (A-Z,a-z) and numbers (0-9) are allowed.");
    document.getElementById("ctl00$ContentPlaceHolder1$txtPassword").focus();
    return(false);
  } 

 return (true);

}